import { defineStore } from 'pinia';

export const useUserStore = defineStore('user', {
  state: () => ({
    user: null,
    jwtToken: null
  }),
  actions: {
    login(userData, token) {
      this.user = userData;
      this.jwtToken = token;
      // 将用户信息存储到会话存储
      sessionStorage.setItem('user', JSON.stringify({
        user: userData,
        jwtToken: token
      }));
    },
    logout() {
      this.user = null;
      this.jwtToken = null;
      sessionStorage.removeItem('user');
    }
  }
});